// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*
 * VM_MagicMethod.h
 *
 *  Created on: Jan 18, 2010
 *      Author: dhovemey
 */

#ifndef VM_MAGICMETHOD_H_
#define VM_MAGICMETHOD_H_

/**
 * @file
 * @brief Definitions related to the native implementation of magic methods.
 */

#include <vector>

class VM_Thread;
class VM_Object;

/**
 * Type of the VM_Thread operand stack.
 */
typedef std::vector<VM_Object *> VM_ThreadOperandStack;

/**
 * Type of native magic method implementations.
 */
typedef VM_Object *(VM_MagicMethod)(VM_Thread *thread, VM_ThreadOperandStack::iterator argIter, unsigned numArgs);

/**
 * In native code, refer to an argument of a magic method.
 * @param n the index of the argument (0 for receiver, 1 for first explicit argument)
 */
#define VM_METHOD_ARG(n) (*(argIter + (n)))

/**
 * In native code, refer to the receiver object of a magic method.
 */
#define VM_RECEIVER      VM_METHOD_ARG(0)

/**
 * In native code, refer to the VM_Interpreter.
 */
#define VM_INTERP        (thread->getInterpreter())

#endif /* VM_MAGICMETHOD_H_ */
